import type { LoadingOptions } from 'element-plus'
import { ElLoading } from 'element-plus'

let loading: {
  close: () => void
}

const loadingOptions = {
  lock: true,
  text: '加載中...',
  // spinner: 'el-icon-loading',
  body: true,
  background: 'rgba(0, 0, 0, 0.1)',
}

class LoadingEvent {
  showLoading(config?: LoadingOptions) {
    loading = ElLoading.service({ ...loadingOptions, ...config })
  }

  hideLoading() {
    loading.close()
  }
}

export default new LoadingEvent()
